﻿/*
 * Code by (c) eDz0r
 * Release topic: http://forum.iv-multiplayer.com/index.php/topic,4605.0.html
 * TODO: Convert to WPF window
 */

using System;
using System.Windows.Forms;

namespace IvmpEditor
{
    public partial class frmColorPicker : Form
    {
        string stringColorHEXRGBA;
        string stringColorRGBA;
        string stringConstantHEXRGBA;
        string stringConstantStringRGBA;

        public frmColorPicker()
        {
            InitializeComponent();
        }
        private void btnSelectColor_Click(object sender, EventArgs e)
        {
            if(dialogColor.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                string stringHEXRGBA;
                string stringRGBA;

                pictureBoxColorPreview.BackColor = dialogColor.Color;

                stringHEXRGBA = string.Format("0x{0:X8}", pictureBoxColorPreview.BackColor.ToArgb());
                stringHEXRGBA = stringHEXRGBA.Remove(stringHEXRGBA.IndexOf("x") + 1, 2);
                stringHEXRGBA = stringHEXRGBA + "FF";

                textboxColorHEXRGBA.Text = stringHEXRGBA;

                stringRGBA = string.Format("{0:X8}", pictureBoxColorPreview.BackColor.ToArgb());
                stringRGBA = stringRGBA.Remove(stringRGBA.IndexOf("x") + 1, 2);
                stringRGBA = "[" + stringRGBA + "FF]";
                textboxColorStringRGBA.Text = stringRGBA;

                stringColorHEXRGBA = stringHEXRGBA;
                stringColorRGBA = stringRGBA;

                if (dialogColor.Color.IsNamedColor)
                    txtConstantName.Text = dialogColor.Color.Name.ToUpper();

                btnGenerate.Enabled = true;
            }
        }
        private void buttonGenerate_Click(object sender, EventArgs e)
        {
            if (txtConstantName.Text == string.Empty)
            {
                MessageBox.Show(Properties.Resources.L_ErrEnterConstantName, Properties.Resources.L_ColorPicker, 
                    MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                stringConstantHEXRGBA = string.Format("const HEX_{0} = {1};", txtConstantName.Text, stringColorHEXRGBA);
                textboxConstanColorHEXRGBA.Text = stringConstantHEXRGBA;

                stringConstantStringRGBA = string.Format("const COLOR_{0} = \"{1}\";", txtConstantName.Text, stringColorRGBA);
                textboxStringRGBA.Text = stringConstantStringRGBA;
            }
        }
        private void menuAbout_Click(object sender, EventArgs e)
        {
            MessageBox.Show(string.Format("Author: eDz0r{0}Testing: NeeR{0}\nBuilded for IV:MP community", Environment.NewLine), 
                string.Format(Properties.Resources.L_About, "Color picker"), MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
        private void frmColorPicker_FormClosing(object sender, FormClosingEventArgs e)
        {
            e.Cancel = true;
            this.Visible = false;
        }
    }
}
